<f:subview xmlns:f="http://java.sun.com/jsf/core"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:c="http://java.sun.com/jstl/core"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:a4j="http://richfaces.org/a4j"
  xmlns:nxu="http://nuxeo.org/nxweb/util"
  xmlns:nxl="http://nuxeo.org/nxforms/layout"
  id="#{widget.id}">

  <c:if test="#{widget.mode != 'edit'}">

    <h:outputText value="#{messages['label.files.noAttachedFiles']}"
      rendered="#{empty field}" />

    <table>
      <tbody>
        <nxu:inputList value="#{field}" id="#{widget.id}_table" model="model"
          rendered="#{not empty field}">
          <nxl:subWidget>
            <tr>
              <td class="fieldColumn">
                <nxl:widget widget="#{widget}"
                  value="#{model.rowData}" />
              </td>
            </tr>
          </nxl:subWidget>
        </nxu:inputList>
      </tbody>
    </table>

  </c:if>

  <c:if test="#{widget.mode == 'edit'}">

    <script type="text/javascript"
      src="#{baseURL}scripts/contextKeeper.js"></script>
    <script type="text/javascript">
      jQuery(document).ready(function(){
        document.NXContextKeeper_#{widget.id} = new InputContextKeeper(jQuery('.jsContextKeeper_#{widget.id}')[0].id);
      });
    </script>

    <a4j:region renderRegionOnly="true" id="#{widget.id}_region">
      <a4j:outputPanel ajaxRendered="true" layout="block"
        id="#{widget.id}_panel" styleClass="jsContextKeeper_#{widget.id}">
        <nxu:inputList value="#{field}" id="#{widget.id}_input" model="model"
          removeEmpty="#{widgetProperty_removeEmpty}"
          number="#{widgetProperty_number}"
          template="#{nxd:propertyDefaultValue(widget.fieldDefinitions[0].propertyName)}"
          required="#{widgetProperty_required}" diff="#{widget.properties['diff']}">

          <h:panelGrid columns="2">
            <a4j:commandLink immediate="true"
              onclick="document.NXContextKeeper_#{widget.id}.removeFromKeeper(#{model.rowIndex});"
              oncomplete="document.NXContextKeeper_#{widget.id}.onReturnAnswer();"
              actionListener="#{editableListBean.performAction}"
              id="#{widget.id}_delete" render="#{widget.id}_input"
              bypassUpdates="true"
              status="#{widget.id}_status">
              <h:graphicImage value="/icons/delete.png" />
              <f:param name="for" value="#{widget.id}_input" />
              <f:param name="index" value="#{model.rowIndex}" />
              <f:param name="type" value="remove" />
            </a4j:commandLink>

            <nxl:subWidget>
              <nxl:widget widget="#{widget}"
                value="#{model.rowData}" />
            </nxl:subWidget>

          </h:panelGrid>

        </nxu:inputList>
        <h:message styleClass="errorMessage" for="#{widget.id}_input"
          id="#{widget.id}_message" />
      </a4j:outputPanel>

      <a4j:commandLink immediate="true"
        oncomplete="document.NXContextKeeper_#{widget.id}.onReturnAnswer();"
        onclick="document.NXContextKeeper_#{widget.id}.onAddFile();"
        actionListener="#{editableListBean.performAction}" id="#{widget.id}_add"
        styleClass="button smallButton"
        status="#{widget.id}_status">
        <f:param name="for" value="#{widget.id}_input" />
        <f:param name="type" value="add" />
        <h:outputText value="#{nxu:test(empty widgetProperty_addLabel, messages['command.addNewAttachedFile'], nxu:test(widget.translated, messages[widgetProperty_addLabel], widgetProperty_addLabel))}" />
      </a4j:commandLink>

      <a4j:status name="#{widget.id}_status">
        <f:facet name="start">
          <h:graphicImage value="/img/standart_waiter.gif" />
        </f:facet>
      </a4j:status>

    </a4j:region>

  </c:if>

</f:subview>
